<?php

/**
 * 系统配置
 * Enter description here ...
 * @author Admin
 *
 */
class ConfigAction extends CommonAction{
	
	/**
	 * 系统参数配置首页
	 * Enter description here ...
	 */
	public function index() {
		$config = D('Config');  //快速实例化模型
		$where = array(
			'stype' =>0    
		);
		
		//$configdata = $config->select($where);
		
		$configdata = $config-> select(array('order'=>'cid' , 'where'=>'stype=0' ));
		
		$this->assign("configdata",$configdata);
		$this->display();
	}
	
	
	
	/**
	 * 保存系统参数配置
	 * Enter description here ...
	 */
	public function save(){
		$data = $_POST;
		
		$config = D('Config');
		$file = ROOT_PATH."/Common/common_cache.php";  //缓存文件
		
		if(!is_writeable($file)){
			$this->error("配置文件'{$file}'不支持写入，无法修改系统配置参数！");
		}
		
		
		$content = "<?php\r\n";
		$content .= "\$sysconfig =array(\r\n";

		foreach ($data as $key=>$val){  //配置页面提交过数据
			$key = Char_cv($key);
			$val = Char_cv($val);
			
			$where['key']=$key;
			$value['val']=$val;
			
			$info = $config->where($where)->save($value);  //根据key设置相应配置值
			
			$content .= "\t'$key'=>'$val',\r\n";  //拼写系统配置缓存文件
		}
		
		unset($data);
		
		$content .= ");\r\n";
		$content .= "\r\n?>";
		
		$return = file_put_contents($file,$content);  //配置内容写入到缓存文件
		
		if ($config->error == null && $return != 0){
			$this->success('修改系统配置成功');
		}else{
			$this->error($config->getError());
		}
		
	}
	
	
}
?>